package com.hongkzh.www.look.media.presenter;

import com.hongkzh.www.look.media.model.bean.HotAdvBean;
import com.hongkzh.www.look.media.view.iview.MedPopIView;
import com.hongkzh.www.other.okhttp.CallBackUtil;
import com.hongkzh.www.other.okhttp.OkhttpUtil;
import com.hongkzh.www.presenter.BasePresenter;

import okhttp3.Call;

import static com.hongkzh.www.other.api.Api.GETHOTADVLISTMEDIAADV;

/**
 * 自媒体 人气
 */
public class MedPopPresenter extends BasePresenter<MedPopIView> {
    private int pageNumber = 1;
    private boolean lastPage = false;

    public MedPopPresenter getHotAdvList() {
        OkhttpUtil.okHttpPost(GETHOTADVLISTMEDIAADV(String.valueOf(pageNumber)), new CallBackUtil<HotAdvBean>() {
            @Override
            public void onFailure(Call call, Exception e) {
                getIView().onError(e);
            }

            @Override
            public void onResponse(HotAdvBean response) {
                lastPage = response.getData().isLastPage();
                if (lastPage) getIView().onLastPage(lastPage);
                getIView().setHotAdvList(response);
            }
        });
        return this;
    }

    public void loadmore() {
        if (!lastPage) {
            pageNumber += 1;
            getHotAdvList();
        }
    }
}
